Skip to content

feat(Pagination): accessibility tweaks & add unit tests#1903

Merged
kasya merged 12 commits intoOWASP:mainfrom
suryansh-it:pagination-clean
Aug 1, 2025
Merged

feat(Pagination): accessibility tweaks & add unit tests#1903
kasya merged 12 commits intoOWASP:mainfrom
suryansh-it:pagination-clean

Conversation

@suryansh-it
Copy link
Contributor

Proposed change

This is a clean version of the earlier PR #1879, which mistakenly included unrelated files.

Closes #1864
Replaces #1879

Summary

This PR introduces:

  • Accessibility improvements to the <Pagination /> component:
    • type="button" on all <Button> elements to prevent unintended form submissions
    • aria-current="page" on the active page for improved screen reader support
    • aria-label="More pages" used for ellipsis indicators instead of data-testid
  • New unit tests in __tests__/unit/components/Pagination.test.tsx that cover:
    • Conditional rendering (e.g. isLoaded = false, totalPages <= 1)
    • Correct pagination number display across edge cases and large sets
    • Prev/Next button enable/disable states
    • Ellipsis logic and placement
    • onPageChange callback functionality
    • Accessibility features and styles

Checklist

  • I've read and followed the contributing guidelines.
  • I've run make check-test locally; all checks and tests passed.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 29, 2025

Summary by CodeRabbit

  • New Features
    • Improved accessibility of the pagination controls, including clearer labeling for screen readers and better indication of the current page.
  • Tests
    • Added comprehensive tests for the pagination component, covering rendering, navigation behavior, edge cases, and accessibility features.

Walkthrough

A new unit test suite was added for the <Pagination /> React component, covering rendering, behavior, event handling, edge cases, and accessibility. The component implementation was updated to improve accessibility by adding button types, aria attributes, and roles to relevant elements.

Changes

Cohort / File(s) Change Summary
Pagination Component Tests
frontend/__tests__/unit/components/Pagination.test.tsx
Added comprehensive unit tests for <Pagination /> covering rendering, props, events, edge cases, and accessibility.
Pagination Component Accessibility
frontend/src/components/Pagination.tsx
Added type="button" to all <Button> elements, improved ellipsis accessibility with role and aria-label, and set aria-current="page" on the active page button.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Assessment against linked issues

Objective Addressed Explanation
Renders successfully with minimal required props, Conditional rendering logic, Prop-based behavior, Event handling, State changes / internal logic, Default values and fallbacks, Text and content rendering, Handles edge cases and invalid inputs, Accessibility roles and labels, DOM structure / classNames / styles (#1864)

Suggested reviewers

  • arkid15r

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 42a6498 and 7aec5ec.

📒 Files selected for processing (2)
  • frontend/__tests__/unit/components/Pagination.test.tsx (1 hunks)
  • frontend/src/components/Pagination.tsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • frontend/src/components/Pagination.tsx
  • frontend/tests/unit/components/Pagination.test.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Run frontend e2e tests
  • GitHub Check: Run frontend unit tests
  • GitHub Check: Run backend tests
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@suryansh-it
Copy link
Contributor Author

This is a clean replacement for #1879, which included unrelated files by mistake.

Only the scoped changes for the Pagination component are included here:

  • Accessibility enhancements (aria-current, explicit type="button")
  • Unit tests covering navigation, edge cases, and ellipsis behavior

thanks for the earlier review! Looking forward to feedback on this cleaned-up version.

@suryansh-it
Copy link
Contributor Author

I've verified the changes locally by running make check — all frontend-related tests and checks passed.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Aug 1, 2025

@kasya
Copy link
Collaborator

kasya commented Aug 1, 2025

I've verified the changes locally by running make check — all frontend-related tests and checks passed.

It doesn't look like that 👀
Screenshot 2025-07-31 at 6 07 26 PM

Ensure you run it as the final step before committing your changes.

Copy link
Collaborator

@kasya kasya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding accessibility issues!
Next time make sure you run make check before committing changes 👌🏼

@kasya kasya enabled auto-merge August 1, 2025 01:18
@kasya kasya added this pull request to the merge queue Aug 1, 2025
Merged via the queue into OWASP:main with commit 61f85d8 Aug 1, 2025
24 checks passed
@suryansh-it
Copy link
Contributor Author

Thanks for adding accessibility issues! Next time make sure you run make check before committing changes 👌🏼

Thank you for the guidance and for bearing with me!☺️
I’ll definitely keep that in mind for future contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add tests for <Pagination> component

2 participants

Comments